package com.pengbei.enshrine.ui.account.userdata;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.luck.picture.lib.animators.AnimationType;
import com.luck.picture.lib.basic.PictureSelector;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.config.SelectMimeType;
import com.luck.picture.lib.config.SelectModeConfig;
import com.luck.picture.lib.engine.CompressFileEngine;
import com.luck.picture.lib.engine.CropFileEngine;
import com.luck.picture.lib.engine.ImageEngine;
import com.luck.picture.lib.engine.UriToFileTransformEngine;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.entity.MediaExtraInfo;
import com.luck.picture.lib.interfaces.OnKeyValueResultCallbackListener;
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
import com.luck.picture.lib.language.LanguageConfig;
import com.luck.picture.lib.style.BottomNavBarStyle;
import com.luck.picture.lib.style.PictureSelectorStyle;
import com.luck.picture.lib.style.PictureWindowAnimationStyle;
import com.luck.picture.lib.style.SelectMainStyle;
import com.luck.picture.lib.style.TitleBarStyle;
import com.luck.picture.lib.utils.DateUtils;
import com.luck.picture.lib.utils.MediaUtils;
import com.luck.picture.lib.utils.PictureFileUtils;
import com.luck.picture.lib.utils.SandboxTransformUtils;
import com.luck.picture.lib.utils.StyleUtils;
import com.pengbei.enshrine.R;
import com.pengbei.enshrine.base.BaseActivity;
import com.pengbei.enshrine.common.dialog.callback.PermissionIntroduceCallBack;
import com.pengbei.enshrine.common.dialog.callback.PictureWayCallBack;
import com.pengbei.enshrine.common.utils.CheckUtils;
import com.pengbei.enshrine.common.utils.CommonUtils;
import com.pengbei.enshrine.common.utils.DialogUtils;
import com.pengbei.enshrine.common.utils.GlideEngine;
import com.pengbei.enshrine.common.utils.GlideUtils;
import com.pengbei.enshrine.common.utils.ImageLoaderUtils;
import com.pengbei.enshrine.common.utils.ToastUtils;
import com.pengbei.enshrine.network.bean.GenderModel;
import com.pengbei.enshrine.network.bean.PermissionIntroduceModel;
import com.yalantis.ucrop.UCrop;
import com.yalantis.ucrop.UCropImageEngine;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import top.zibin.luban.CompressionPredicate;
import top.zibin.luban.Luban;
import top.zibin.luban.OnNewCompressListener;
import top.zibin.luban.OnRenameListener;

public class UserDataActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "tupian";
    private TitleBar tbTitle;
    private RelativeLayout rlUdHead;
    private ImageView imgUdHead;
    private RelativeLayout rlUdNickname;
    private TextView tvUdNickname;
    private RelativeLayout rlUdPhone;
    private TextView tvUdPhone;
    private RelativeLayout rlUdEmail;
    private TextView tvUdEmail;
    private RelativeLayout rlUdBirthday;
    private TextView tvUdBirthday;
    private RelativeLayout rlUdGender;
    private TextView tvUdGender;

    private TimePickerView pvTime;
    private OptionsPickerView typepicker;
    private int typeselectoption = 0;
    private String gender = "1";
    private List<String> optiondatalist = new ArrayList<String>();
    private List<GenderModel> genderlist = new ArrayList<GenderModel>();
    private PictureSelectorStyle selectorStyle;
    private int chooseMode = SelectMimeType.ofAll();
    private int animationMode = AnimationType.DEFAULT_ANIMATION;
    private int language = LanguageConfig.SYSTEM_LANGUAGE;
    private ImageEngine imageEngine;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_userdata);
        selectorStyle = new PictureSelectorStyle();
        initOptionData();
        initView();
        setstyle();
    }

    private void initView() {
        tbTitle = findViewById(R.id.tb_title);
        rlUdHead = findViewById(R.id.rl_ud_head);
        imgUdHead = findViewById(R.id.img_ud_head);
        rlUdNickname = findViewById(R.id.rl_ud_nickname);
        tvUdNickname = findViewById(R.id.tv_ud_nickname);
        rlUdPhone = findViewById(R.id.rl_ud_phone);
        tvUdPhone = findViewById(R.id.tv_ud_phone);
        rlUdEmail = findViewById(R.id.rl_ud_email);
        tvUdEmail = findViewById(R.id.tv_ud_email);
        rlUdBirthday = findViewById(R.id.rl_ud_birthday);
        tvUdBirthday = findViewById(R.id.tv_ud_birthday);
        rlUdGender = findViewById(R.id.rl_ud_gender);
        tvUdGender = findViewById(R.id.tv_ud_gender);

        rlUdHead.setOnClickListener(this);
        rlUdNickname.setOnClickListener(this);
        rlUdPhone.setOnClickListener(this);
        rlUdEmail.setOnClickListener(this);
        rlUdBirthday.setOnClickListener(this);
        rlUdGender.setOnClickListener(this);

        tbTitle.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(TitleBar titleBar) {
                finish();
            }
        });
    }

    private void initOptionData(){
        optiondatalist.add(getString(R.string.lc_common_male));
        optiondatalist.add(getString(R.string.lc_common_female));
        optiondatalist.add(getString(R.string.lc_common_secrecy));
        for (int i = 0; i < optiondatalist.size(); i++) {
            GenderModel model = new GenderModel();
            model.setId((i + 1) + "");
            model.setText(optiondatalist.get(i).trim());
            genderlist.add(model);
        }
    }

    @Override
    public void onClick(View v) {
        if (!CheckUtils.isFastDoubleClick()) {
            switch (v.getId()) {
                case R.id.rl_ud_head://头像
                    DialogUtils.showChoicePictureWay(UserDataActivity.this, new PictureWayCallBack() {
                        @Override
                        public void takePicture() {
                            showPermissionDialog(1);
                        }

                        @Override
                        public void photoAlbum() {
                            showPermissionDialog(2);
                        }

                        @Override
                        public void cancal() {

                        }
                    });
                    break;
                case R.id.rl_ud_nickname://昵称

                    break;
                case R.id.rl_ud_phone://手机号

                    break;
                case R.id.rl_ud_email://邮箱

                    break;
                case R.id.rl_ud_birthday://出生日期
                    chooseBirthday();
                    break;
                case R.id.rl_ud_gender://性别
                    showGender(optiondatalist);
                    break;
            }
        }
    }

    private void showPermissionDialog(int way){
        if(
                CheckUtils.checkPermission(this, CommonUtils.permission_image)
                ||CheckUtils.checkPermission(this,CommonUtils.permission_video)
                ||CheckUtils.checkPermission(this,CommonUtils.permission_audio)
                ||CheckUtils.checkPermission(this,CommonUtils.permission_camera))
        {
            List<PermissionIntroduceModel> permissionlist = new ArrayList<PermissionIntroduceModel>();

            PermissionIntroduceModel model1 = new PermissionIntroduceModel();
            model1.setName(getString(R.string.permission3));
            model1.setContent(getString(R.string.permission5));
            permissionlist.add(model1);

            PermissionIntroduceModel model2 = new PermissionIntroduceModel();
            model2.setName(getString(R.string.permission4));
            model2.setContent(getString(R.string.permission5));
            permissionlist.add(model2);

            DialogUtils.showPermissionIntroduceDialog(this, permissionlist, new PermissionIntroduceCallBack() {
                @Override
                public void Sure() {
                    getPermission(way);
                }

                @Override
                public void Cancal() {

                }
            });
        }else {
            getPhoto(way);
        }
    }

    private void getPermission(int way){
        XXPermissions
                .with(this)
                .permission(Permission.READ_MEDIA_IMAGES)
                .permission(Permission.READ_MEDIA_VIDEO)
                .permission(Permission.READ_MEDIA_AUDIO)
                .permission(Permission.CAMERA)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
                        if (allGranted){
                            getPhoto(way);
                        }else {
                            ToastUtils.showError(getString(R.string.lc_common_permissionfail));
                        }
                    }

                    @Override
                    public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
                        ToastUtils.showError(getString(R.string.lc_common_permissionfail));
                    }
                });
    }

    private void getPhoto(int way){
        switch (way){
            case 1://拍照
                PictureSelector.create(this)
                        .openCamera(SelectMimeType.ofImage())
                        .setLanguage(language)
                        .setCropEngine(getCropFileEngine(true))//自定义裁剪
                        .setCompressEngine(getCompressFileEngine(true))//自定义压缩
                        .setSandboxFileEngine(new MeSandboxFileEngine())//自定义沙盒文件处理
                        .forResult(new OnResultCallbackListener<LocalMedia>() {
                            @Override
                            public void onResult(ArrayList<LocalMedia> result) {
                                analyticalSelectResults(result);
                            }

                            @Override
                            public void onCancel() {

                            }
                        });
                break;
            case 2://相册
                PictureSelector.create(this)
                        .openSystemGallery(SelectMimeType.ofImage())
                        .setSelectionMode(SelectModeConfig.SINGLE)//多选or单选
                        .setCropEngine(getCropFileEngine(true))//自定义裁剪
                        .setCompressEngine(getCompressFileEngine(true))//自定义压缩
                        .setSandboxFileEngine(new MeSandboxFileEngine())//自定义沙盒文件处理
                        .forSystemResult(new OnResultCallbackListener<LocalMedia>() {
                            @Override
                            public void onResult(ArrayList<LocalMedia> result) {
                                analyticalSelectResults(result);
                            }

                            @Override
                            public void onCancel() {

                            }
                        });
                break;
        }
    }

    /**
     * 处理选择结果
     *
     * @param result
     */
    private void analyticalSelectResults(ArrayList<LocalMedia> result) {
        for (LocalMedia media : result) {
            if (media.getWidth() == 0 || media.getHeight() == 0) {
                if (PictureMimeType.isHasImage(media.getMimeType())) {
                    MediaExtraInfo imageExtraInfo = MediaUtils.getImageSize(this, media.getPath());
                    media.setWidth(imageExtraInfo.getWidth());
                    media.setHeight(imageExtraInfo.getHeight());
                } else if (PictureMimeType.isHasVideo(media.getMimeType())) {
                    MediaExtraInfo videoExtraInfo = MediaUtils.getVideoSize(this, media.getPath());
                    media.setWidth(videoExtraInfo.getWidth());
                    media.setHeight(videoExtraInfo.getHeight());
                }
            }
            Log.i(TAG, "文件名: " + media.getFileName());
            Log.i(TAG, "是否压缩:" + media.isCompressed());
            Log.i(TAG, "压缩:" + media.getCompressPath());
            Log.i(TAG, "初始路径:" + media.getPath());
            Log.i(TAG, "绝对路径:" + media.getRealPath());
            Log.i(TAG, "是否裁剪:" + media.isCut());
            Log.i(TAG, "裁剪路径:" + media.getCutPath());
            Log.i(TAG, "是否开启原图:" + media.isOriginal());
            Log.i(TAG, "原图路径:" + media.getOriginalPath());
            Log.i(TAG, "沙盒路径:" + media.getSandboxPath());
            Log.i(TAG, "水印路径:" + media.getWatermarkPath());
            Log.i(TAG, "视频缩略图:" + media.getVideoThumbnailPath());
            Log.i(TAG, "原始宽高:" + media.getWidth() + "x" + media.getHeight());
            Log.i(TAG, "裁剪宽高:" + media.getCropImageWidth() + "x" + media.getCropImageHeight());
            Log.i(TAG, "原文件大小:" + PictureFileUtils.formatAccurateUnitFileSize(media.getSize()));
            Log.i(TAG, "文件时长:" + media.getDuration());
            Log.i(TAG, "最终路径:" + media.getAvailablePath());

            //最终路径
            String path = media.getAvailablePath()+"";
            GlideUtils.LoadHeadObject(UserDataActivity.this,imgUdHead,PictureMimeType.isContent(result.get(0).getAvailablePath()) && !result.get(0).isCut() && !result.get(0).isCompressed() ? Uri.parse(path): path);

        }

    }



    /**
     * 选择出生日期
     */
    private void chooseBirthday() {
        Calendar selectedDate = Calendar.getInstance();
        if (!TextUtils.isEmpty(tvUdBirthday.getText().toString().trim())) {
            try {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                Date date = format.parse(tvUdBirthday.getText().toString().trim() + "");
                selectedDate.setTime(date);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        Calendar startDate = Calendar.getInstance();
        Calendar endDate = Calendar.getInstance();
        //正确设置方式 原因：注意事项有说明
        startDate.set(1901, 0, 1);

        pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                tvUdBirthday.setText(new SimpleDateFormat("yyyy-MM-dd").format(date));
            }
        })
                .setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                .setCancelText(getString(R.string.lc_common_cancal))//取消按钮文字
                .setSubmitText(getString(R.string.lc_common_sure))//确认按钮文字
                .setContentTextSize(18)//滚轮文字大小
                .setTitleSize(15)//标题文字大小
                .setTitleText("")//标题文字
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(false)//是否循环滚动
                .setTitleColor(Color.BLACK)//标题文字颜色
                .setSubmitColor(Color.BLUE)//确定按钮文字颜色
                .setCancelColor(Color.RED)//取消按钮文字颜色
                .setTitleBgColor(0xFFFFFFFF)//标题背景颜色 Night mode
                .setBgColor(0xFFFFFFFF)//滚轮背景颜色 Night mode
                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(startDate, endDate)//起始终止年月日设定
                .setLabel(getString(R.string.lc_common_year), getString(R.string.lc_common_month), getString(R.string.lc_common_day), getString(R.string.lc_common_hour), getString(R.string.lc_common_min), getString(R.string.lc_common_second))//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setItemVisibleCount(3)
                .setLineSpacingMultiplier(3.0f)
                .isDialog(false)//是否显示为对话框样式
                .setDecorView((ViewGroup) getWindow().getDecorView().findViewById(R.id.rl_gen))
                .setLayoutRes(R.layout.layout_time, new CustomListener() {
                    @Override
                    public void customLayout(View v) {

                        final TextView tv_time_sure = (TextView) v.findViewById(R.id.tv_time_sure);
                        final TextView tv_time_cancal = (TextView) v.findViewById(R.id.tv_time_cancal);

                        tv_time_sure.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvTime.returnData();
                                pvTime.dismiss();

                            }
                        });
                        tv_time_cancal.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvTime.dismiss();
                            }
                        });
                    }
                })
                .build();
        pvTime.show();
    }

    /**
     * 选择性别
     */
    private void showGender(List<String> optiondatalist) {

        typeselectoption = 0;
        if (!TextUtils.isEmpty(gender)) {
            for (int i = 0; i < genderlist.size(); i++) {
                if (TextUtils.equals(genderlist.get(i).getId(), gender)) {
                    typeselectoption = i;
                    break;
                }
            }
        }

        typepicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                gender = genderlist.get(options1).getId();
                tvUdGender.setText(genderlist.get(options1).getText());
            }
        })
                .setDividerColor(getResources().getColor(R.color.color_line))
                .setTextColorCenter(getResources().getColor(R.color.color_000000)) //设置选中项文字颜色
                .isAlphaGradient(true)
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .setItemVisibleCount(5)
                .setContentTextSize(16)
                .setSelectOptions(typeselectoption)
//                .setOutSideColor(getResources().getColor(R.color.color_transparent))
                .setLineSpacingMultiplier(3.0f)
                .setDecorView((ViewGroup) getWindow().getDecorView().findViewById(R.id.rl_gen))
                .setLayoutRes(R.layout.layout_optionswheel, new CustomListener() {
                    @Override
                    public void customLayout(View v) {
                        final TextView tv_sure = (TextView) v.findViewById(R.id.tv_option_sure);
                        final TextView tv_cancal = (TextView) v.findViewById(R.id.tv_option_cancal);
                        tv_sure.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                typepicker.returnData();
                                typepicker.dismiss();
                            }
                        });
                        tv_cancal.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                typepicker.dismiss();
                            }
                        });
                    }
                })
                .build();
        typepicker.setPicker(optiondatalist);
        typepicker.show();

    }

    /**
     * 压缩引擎
     *
     * @return
     */
    private ImageFileCompressEngine getCompressFileEngine(boolean compress) {
        return compress ? new ImageFileCompressEngine() : null;
    }

    /**
     * 自定义压缩
     */
    private static class ImageFileCompressEngine implements CompressFileEngine {
        @Override
        public void onStartCompress(Context context, ArrayList<Uri> source, OnKeyValueResultCallbackListener call) {
            Luban.with(context).load(source).isUseIOBufferPool(false).ignoreBy(100).setRenameListener(new OnRenameListener() {
                @Override
                public String rename(String filePath) {
                    int indexOf = filePath.lastIndexOf(".");
                    String postfix = indexOf != -1 ? filePath.substring(indexOf) : ".jpg";
                    return DateUtils.getCreateFileName("CMP_") + postfix;
                }
            }).filter(new CompressionPredicate() {
                @Override
                public boolean apply(String path) {
                    if (PictureMimeType.isUrlHasImage(path) && !PictureMimeType.isHasHttp(path)) {
                        return true;
                    }
                    return !PictureMimeType.isUrlHasGif(path);
                }
            }).setCompressListener(new OnNewCompressListener() {
                @Override
                public void onStart() {

                }

                @Override
                public void onSuccess(String source, File compressFile) {
                    if (call != null) {
                        call.onCallback(source, compressFile.getAbsolutePath());
                        CommonUtils.Logs("======", "压缩后文件大小: " + PictureFileUtils.formatAccurateUnitFileSize(compressFile.length()));
                    }
                }

                @Override
                public void onError(String source, Throwable e) {
                    if (call != null) {
                        call.onCallback(source, null);
                    }
                }
            }).launch();
        }
    }

    /**
     * 自定义沙盒文件处理
     */
    private static class MeSandboxFileEngine implements UriToFileTransformEngine {

        @Override
        public void onUriToFileAsyncTransform(Context context, String srcPath, String mineType, OnKeyValueResultCallbackListener call) {
            if (call != null) {
                call.onCallback(srcPath, SandboxTransformUtils.copyPathToSandbox(context, srcPath, mineType));
            }
        }
    }

    /**
     * 创建自定义输出目录
     *
     * @return
     */
    private String getSandboxPath() {
        File externalFilesDir = getExternalFilesDir("");
        File customFile = new File(externalFilesDir.getAbsolutePath(), "Sandbox");
        if (!customFile.exists()) {
            customFile.mkdirs();
        }
        return customFile.getAbsolutePath() + File.separator;
    }

    private String[] getNotSupportCrop() {
        if (true) {
            return new String[]{PictureMimeType.ofGIF(), PictureMimeType.ofWEBP()};
        }
        return null;
    }

    /**
     * 裁剪引擎
     *
     * @return
     */
    private ImageFileCropEngine getCropFileEngine(boolean crop) {
        return crop ? new ImageFileCropEngine() : null;
    }

    /**
     * 自定义裁剪
     */
    private class ImageFileCropEngine implements CropFileEngine {
        @Override
        public void onStartCrop(Fragment fragment, Uri srcUri, Uri destinationUri, ArrayList<String> dataSource, int requestCode) {
            UCrop.Options options = buildOptions();
            UCrop uCrop = UCrop.of(srcUri, destinationUri, dataSource);
            uCrop.withOptions(options);
            uCrop.setImageEngine(new UCropImageEngine() {
                @Override
                public void loadImage(Context context, String url, ImageView imageView) {
                    if (!ImageLoaderUtils.assertValidRequest(context)) {
                        return;
                    }
                    Glide.with(context).load(url).override(180, 180).into(imageView);
                }

                @Override
                public void loadImage(Context context, Uri url, int maxWidth, int maxHeight, OnCallbackListener<Bitmap> call) {
                    Glide.with(context).asBitmap().load(url).override(maxWidth, maxHeight).into(new CustomTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                            if (call != null) {
                                call.onCall(resource);
                            }
                        }

                        @Override
                        public void onLoadCleared(@Nullable Drawable placeholder) {
                            if (call != null) {
                                call.onCall(null);
                            }
                        }
                    });
                }
            });
            uCrop.start(fragment.requireActivity(), fragment, requestCode);
        }
    }

    /**
     * 裁剪比例
     */
    private int aspect_ratio_x = 1, aspect_ratio_y = 1;

    /**
     * 配制UCrop，可根据需求自我扩展
     *
     * @return
     */
    private UCrop.Options buildOptions() {
        UCrop.Options options = new UCrop.Options();
        options.setHideBottomControls(true);//是否显示裁剪菜单栏
        options.setFreeStyleCropEnabled(true);//裁剪框or图片拖动
        options.setShowCropFrame(true);//是否显示裁剪边框
        options.setShowCropGrid(true);//是否显示裁剪框网格
        options.setCircleDimmedLayer(true);//圆形头像裁剪模式
        options.withAspectRatio(aspect_ratio_x, aspect_ratio_y);
        options.setCropOutputPathDir(getSandboxPath());
        options.isCropDragSmoothToCenter(false);
        options.setSkipCropMimeType(getNotSupportCrop());
        options.isForbidCropGifWebp(true);//禁止裁剪gif
        options.isForbidSkipMultipleCrop(true);
        options.setMaxScaleMultiplier(100);
        if (selectorStyle != null && selectorStyle.getSelectMainStyle().getStatusBarColor() != 0) {
            SelectMainStyle mainStyle = selectorStyle.getSelectMainStyle();
            boolean isDarkStatusBarBlack = mainStyle.isDarkStatusBarBlack();
            int statusBarColor = mainStyle.getStatusBarColor();
            options.isDarkStatusBarBlack(isDarkStatusBarBlack);
            if (StyleUtils.checkStyleValidity(statusBarColor)) {
                options.setStatusBarColor(statusBarColor);
                options.setToolbarColor(statusBarColor);
            } else {
                options.setStatusBarColor(ContextCompat.getColor(this, R.color.ps_color_grey));
                options.setToolbarColor(ContextCompat.getColor(this, R.color.ps_color_grey));
            }
            TitleBarStyle titleBarStyle = selectorStyle.getTitleBarStyle();
            if (StyleUtils.checkStyleValidity(titleBarStyle.getTitleTextColor())) {
                options.setToolbarWidgetColor(titleBarStyle.getTitleTextColor());
            } else {
                options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.ps_color_white));
            }
        } else {
            options.setStatusBarColor(ContextCompat.getColor(this, R.color.ps_color_grey));
            options.setToolbarColor(ContextCompat.getColor(this, R.color.ps_color_grey));
            options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.ps_color_white));
        }
        return options;
    }

    /**
     * 设置相机风格
     */
    private void setstyle() {

        TitleBarStyle whiteTitleBarStyle = new TitleBarStyle();
        whiteTitleBarStyle.setTitleBackgroundColor(ContextCompat.getColor(this, R.color.ps_color_white));
        whiteTitleBarStyle.setTitleDrawableRightResource(R.drawable.vector_down);
        whiteTitleBarStyle.setTitleLeftBackResource(R.drawable.ps_ic_black_back);
        whiteTitleBarStyle.setTitleTextColor(ContextCompat.getColor(this, R.color.ps_color_black));
        whiteTitleBarStyle.setTitleCancelTextColor(ContextCompat.getColor(this, R.color.ps_color_53575e));
        whiteTitleBarStyle.setDisplayTitleBarLine(true);

        BottomNavBarStyle whiteBottomNavBarStyle = new BottomNavBarStyle();
        whiteBottomNavBarStyle.setBottomNarBarBackgroundColor(ContextCompat.getColor(this, R.color.ps_color_e));
        whiteBottomNavBarStyle.setBottomPreviewSelectTextColor(ContextCompat.getColor(this, R.color.ps_color_53575e));

        whiteBottomNavBarStyle.setBottomPreviewNormalTextColor(ContextCompat.getColor(this, R.color.ps_color_9b));
        whiteBottomNavBarStyle.setBottomPreviewSelectTextColor(ContextCompat.getColor(this, R.color.ps_color_fa632d));
        whiteBottomNavBarStyle.setCompleteCountTips(false);
        whiteBottomNavBarStyle.setBottomEditorTextColor(ContextCompat.getColor(this, R.color.ps_color_53575e));
        whiteBottomNavBarStyle.setBottomOriginalTextColor(ContextCompat.getColor(this, R.color.ps_color_53575e));

        SelectMainStyle selectMainStyle = new SelectMainStyle();
        selectMainStyle.setStatusBarColor(ContextCompat.getColor(this, R.color.ps_color_white));
        selectMainStyle.setSelectNumberStyle(true);
        selectMainStyle.setPreviewSelectNumberStyle(true);
//        selectMainStyle.setSelectBackground(R.drawable.ps_demo_blue_num_selector);
        selectMainStyle.setMainListBackgroundColor(ContextCompat.getColor(this, R.color.ps_color_white));
//        selectMainStyle.setPreviewSelectBackground(R.drawable.ps_demo_preview_blue_num_selector);
        selectMainStyle.setSelectNormalTextColor(ContextCompat.getColor(this, R.color.ps_color_9b));
        selectMainStyle.setSelectTextColor(ContextCompat.getColor(this, R.color.ps_color_blue));
        selectMainStyle.setSelectText(R.string.ps_completed);

        PictureWindowAnimationStyle animationStyle = new PictureWindowAnimationStyle();
        animationStyle.setActivityEnterAnimation(R.anim.ps_anim_up_in);
        animationStyle.setActivityExitAnimation(R.anim.ps_anim_down_out);

        chooseMode = SelectMimeType.ofImage();//全部类型文件
        language = LanguageConfig.SYSTEM_LANGUAGE;//语言
        animationMode = AnimationType.SLIDE_IN_BOTTOM_ANIMATION;//动画

        selectorStyle.setWindowAnimationStyle(animationStyle);
        selectorStyle.setTitleBarStyle(whiteTitleBarStyle);
        selectorStyle.setBottomBarStyle(whiteBottomNavBarStyle);
        selectorStyle.setSelectMainStyle(selectMainStyle);

        imageEngine = GlideEngine.createGlideEngine();

    }

    public static void goToThisActivity(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, UserDataActivity.class);
        context.startActivity(intent);
    }

}
